<?php
$page=$_GET['page']??1;
$limit=5;
$start=($page-1)*$limit;
$memcache=memcache_connect('127.0.0.1',11211);
//memcache_flush($memcache);
$arr=$memcache->get($page);
if($arr=='') {
    echo "没有缓存";
    $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
    $sql="select * from goods limit $start,$limit";
    $arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
    $memcache->set($page,$arr);
}
else
{
    $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
    $sql="select * from goods limit $start,$limit";
    $arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}



//$last=count($arr);
//$number=ceil($last/$limit);
?>
<table border="1">
    <tr>
        <td>编号</td>
        <td>商品名称</td>
        <td>商品分类</td>
        <td>商品品牌</td>
        <td>商品价格</td>
        <td>商品库存</td>
        <td>商品详情</td>
    </tr>
    <?php foreach($arr as $key=>$value) { ?>
        <tr>
            <td><?php echo $value['id']?></td>
            <td><?php echo $value['goods_name']?></td>
            <td><?php echo $value['goods_fl']?></td>
            <td><?php echo $value['goods_brand']?></td>
            <td><?php echo $value['goods_price']?></td>
            <td><?php echo $value['goods_many']?></td>
            <td>
                <a href="xx.php?id=<?php echo $value['id']?>">商品详情</a>
            </td>
        </tr>
    <?php } ?>
</table>
<a href="page.php?page=1">首页</a>
<a href="page.php?page=<?php echo $page-1?>">上一页</a>
<a href="page.php?page=<?php echo $page+1?>">下一页</a>
<a href="page.php?page=2">尾页</a>
